package com.two.screen.water.balance.widget.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.widget.TextView
import butterknife.BindView
import butterknife.ButterKnife
import com.two.screen.water.balance.R
import com.two.screen.water.balance.ui.App
import com.two.screen.water.balance.utils.DialogUtil

class LoadingDialog(context: Context?, var mTitle: String? = "正在加载...") : Dialog(context!!, R.style.MyDialog) {
    @BindView(R.id.loading_title_tv)
    lateinit var titleTv: TextView

    //constructor(context: Context?) : this(context, App.context!!.getString(R.string.loading_now))

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_loading)
        this.setCanceledOnTouchOutside(false)
        setCancelable(false)
        setAttributes()
        ButterKnife.bind(this)
        titleTv.text = mTitle
    }

    /**
     * 设置对话框窗口属性
     */
    private fun setAttributes() {
        val dialogWindow = window
        val lp = dialogWindow!!.attributes
        lp.width = App.screenWidth
        lp.height = App.screenHeight
        dialogWindow.attributes = lp
        //TODO:设置不可取消。
        dialogWindow.setGravity(Gravity.CENTER)
    }

    override fun onBackPressed() {
        super.onBackPressed()
    }


    fun setTitleTv(title: String) {
        mTitle = title
        titleTv.text = mTitle
    }

    override fun show() {
        super.show()
        //隐藏状态栏
        window?.let { DialogUtil.hideNavigationBar(it) }
    }
}
